package com.BallPlayer.tools;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateValidator {
    public static boolean isValidDate(String dateString) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        format.setLenient(false);

        try {
            format.parse(dateString);
            return true;
        } catch (ParseException e) {
            return false;
        }
    }
    public static Date convertStringToDate(String dateString) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        try {
            return dateFormat.parse(dateString);
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static void main(String[] args) {
        String date1 = "2023-07-05";
        String date2 = "2023/07/05";
        String date3 = "2023-02-30";
        String date4 = "abc123";

        System.out.println(date1 + " is valid date: " + isValidDate(date1));
        System.out.println(date2 + " is valid date: " + isValidDate(date2));
        System.out.println(date3 + " is valid date: " + isValidDate(date3));
        System.out.println(date4 + " is valid date: " + isValidDate(date4));
    }
}